#!/bin/bash

# Test recovery when we have less zones availability

. ./common

for i in `seq 0 7`; do
    _start_sheep $i
done

_wait_for_sheep 8

_cluster_format -c 6

_vdi_create test 100M
# create 25 objects
for i in `seq 0 24`; do
    echo $i | $DOG vdi write test $((i * 4 * 1024 * 1024)) 512
done

$DOG vdi read test | md5sum

for i in `seq 7 -1 0`; do
    _wait_for_sheep_recovery 0
    _kill_sheep $i
done

sleep 1

# start master first to avoid master transfer
_start_sheep 0
_wait_for_sheep 1
for i in `seq 1 7`; do
    _start_sheep $i
done

_wait_for_sheep 8
_wait_for_sheep_recovery 0

ls $STORE/*/{obj,d[0-9]*}/807c2b2500000000 2> /dev/null | \
	_filter_store | _filter_md_store | sort
for i in `seq 0 24`; do
    ls $STORE/*/{obj,d[0-9]*}/007c2b25000000`printf "%02x" $i` 2> /dev/null | \
		_filter_store | _filter_md_store | sort
done
ls $STORE/*/{obj,d[0-9]*}/.stale 2> /dev/null | \
	_filter_store | _filter_md_store | sort -u

$DOG vdi read test | md5sum
